package provajbehave;

public class Contatore {

	private int value;
	private final int MAX;

	public Contatore(int max) {
		if (max <= 0) {
			throw new RuntimeException(
					"Max value must be greater than zero. Input: " + max);
		}
		value = 0;
		MAX = max;
	}

	public int getValue() {
		return value;
	}

	public void incrementOf(int x) {
		if (value + x > MAX) {
			value = value + x - MAX - 1;
		} else {
			value = value + x;
		}
	}

	public void reset() {
		value = 0;
	}

	public void decrementOf(int x) {
		if (value - x < 0) {
			value = 0;
		} else {
			value = value - x;
		}
	}

}
